﻿Imports System.Data.OleDb
Public Class NhanVienDAO
    Public Function GetNhanVien() As DataTable
        Dim sql As String = "select * from NhanVien"
        Dim dt As New DataTable
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim da As New OleDbDataAdapter(sql, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub AddNhanVien(ByVal newNV As NhanVienDTO)
        Dim sql As String = String.Format("insert into NhanVien(MaNV,TenNV,NgaySinh,GioiTinh,MaBangCap,DienThoai,DiaChi,MaCV,CMND) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", _
                                           newNV.MaNV, newNV.TenNV, newNV.NgaySinh, newNV.GioiTinh, newNV.MaBangCap, newNV.DienThoai, newNV.DiaChi, newNV.ChucVu, newNV.CMND, newNV.MaNV)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Dữ liêu bị sai vui lòng kiểm tra lại !")
        End Try
        cn.Close()
    End Sub

    Public Sub DelNhanVien(ByVal delNV As NhanVienDTO)
        Dim sql As String = String.Format("delete from NhanVien where STT={0}", delNV.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(Sql, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Sub UpdateNhanVien(ByVal newNV As NhanVienDTO)
        Dim sql As String = String.Format("update NhanVien set MaNV='{0}',TenNV='{1}',NgaySinh='{2}',GioiTinh='{3}',MaBangCap='{4}',DienThoai='{5}',DiaChi='{6}',MaCV='{7}',CMND='{8}' where STT={9}", _
                                          newNV.MaNV, newNV.TenNV, newNV.NgaySinh, newNV.GioiTinh, newNV.MaBangCap, newNV.DienThoai, newNV.DiaChi, newNV.ChucVu, newNV.CMND, newNV.STT)
        Dim cn As OleDbConnection = DataProvider.OpenConnect
        Dim cmd As New OleDbCommand(sql, cn)
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Vui lòng kiểu tra lại dữ liệu !")
        End Try
        cn.Close()
    End Sub
End Class
